resource "google_cloud_identity_group" "group" {
  display_name = "<%= ctx[:vars]['id_group'] %>"

  parent = "customers/<%= ctx[:test_env_vars]['cust_id'] %>"

  group_key {
  	id = "<%= ctx[:vars]['id_group'] %>@<%= ctx[:test_env_vars]['org_domain'] %>"
  }

  labels = {
    "cloudidentity.googleapis.com/groups.discussion_forum" = ""
  }
}

resource "google_cloud_identity_group" "child-group" {
  display_name = "<%= ctx[:vars]['id_group'] %>-child"

  parent = "customers/<%= ctx[:test_env_vars]['cust_id'] %>"

  group_key {
  	id = "<%= ctx[:vars]['id_group'] %>-child@<%= ctx[:test_env_vars]['org_domain'] %>"
  }

  labels = {
    "cloudidentity.googleapis.com/groups.discussion_forum" = ""
  }
}

resource "google_cloud_identity_group_membership" "<%= ctx[:primary_resource_id] %>" {
  group    = google_cloud_identity_group.group.id

  preferred_member_key {
    id = google_cloud_identity_group.child-group.group_key[0].id
  }

  roles {
  	name = "MEMBER"
  }
}
